<?php

namespace App\Http\Controllers\Admin;

use App\Http\Models\Subject;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Response;

class SubjectController extends Controller
{
    public function lst()
    {
        $size = 2;
        $subjectData = Subject::paginate($size);

        return view('admin.subject.lst', compact('subjectData'));
    }

    // 学科添加
    public function add(Request $request)
    {
        if($request->isMethod('POST')){
            //表单数据接收
            $data = $request->except(['_token']);
            $status = Subject::create($data);
            if($status){
                // 成功上传
                return Response::json([
                    'status' => 'success',
                    'code' => 1000,
                    'msg' => '学科添加成功！',
                    'data' => $status,
                ]);
            }else{
                // 失败
                return Response::json([
                    'status' => 'failure',
                    'code' => 1002,
                    'msg' => '学科添加失败！',
                ]);
            }



        }
        return view('admin.subject.add');
    }


}
